#include "cell_main.h"
#include "ui_cell_main.h"
#include <QPushButton>
#include <QDebug>

Cell_Main::Cell_Main(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Cell_Main),
    //界面指针需要初始化为空
    m_bookPage(nullptr),
    m_userPage(nullptr),
    m_recordPage(nullptr)
{
    ui->setupUi(this);
    initPage();
}

Cell_Main::~Cell_Main()
{
    delete ui;
}

void Cell_Main::initPage()
{
    m_userPage = new Cell_UserMgr(this);
    m_bookPage = new Cell_BookMgr(this);
    m_recordPage = new Cell_record(this);

    ui->stackedWidget->addWidget(m_userPage);
    ui->stackedWidget->addWidget(m_bookPage);
    ui->stackedWidget->addWidget(m_recordPage);

    ui->stackedWidget->setCurrentIndex(0);

    auto childWidgetList = ui->tool->children();
    for(auto child : childWidgetList){
        if(child->objectName().contains("btn")){
            connect(static_cast<QPushButton *>(child),&QPushButton::clicked, this, &Cell_Main::dealMenu);
        }
    }

}

void Cell_Main::dealMenu(){

    qDebug() << sender()->objectName();

    auto str = sender()->objectName();

    do{
        if("btn_user" == str){
            ui->stackedWidget->setCurrentIndex(0);
            break;
        }

        if("btn_book" == str){
            ui->stackedWidget->setCurrentIndex(1);
            break;
        }

        if("btn_his" == str){
            ui->stackedWidget->setCurrentIndex(2);
            break;
        }

    }while(false);

}
